# -*- coding:utf-8 -*-
__author__ = 'lu'

import pysvn
from pylib.utils import *

def get_svn_url(path):
    try:
        log("get svn url %s" % path)
        client = pysvn.Client()
        entry = client.info(path)
        return entry.url
    except Exception as e:
        log(e)
        return "";


def svn_update(path):
    log("update svn %s" % path)
    client = pysvn.Client()
    client.cleanup(path)
    client.update(path)
    entry = client.info(path)
    number = entry.commit_revision.number
    return number


def svn_commit_file(file, comment):
    log("commit svn %s(%s)" % (file, comment))
    client = pysvn.Client()

    _comment = 'SuperX Team AutoBuild Tools(STAT,一个依靠写代码为生的群体) commit svn\n%s' % comment
    client.checkin([file], _comment)


def svn_checkout(url, path):
    log("checkout svn from %s to %s" % (url, path))
    client = pysvn.Client()
    client.checkout(url, path)
